package com.bw.heishou.mvp.presenter;

import android.util.Log;

import com.blankj.utilcode.util.ToastUtils;
import com.bw.heishou.Bean.UserBean;
import com.bw.heishou.mvp.contract.UserContract;
import com.bw.lib_core.mvp.presenter.BasePresenter;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

public class LogPresenter extends BasePresenter<UserContract.User_Model,UserContract.User_View> {
    private static final String TAG = "LogPresenter";
    public LogPresenter(UserContract.User_Model mmodel, UserContract.User_View vview) {
        super(mmodel, vview);
    }

    public void regrequest(String url,String user,String pass){
        Mmodel.reg(url,user, pass, new Observer<UserBean>() {
            @Override
            public void onSubscribe( Disposable d) {
                Log.i(TAG, "regrequest-onSubscribe: ");
            }

            @Override
            public void onNext( UserBean userBean) {
                Log.i(TAG, "regrequest-onNext: ");
                if (userBean.msg.equals("操作成功！")){
                    Vview.logOk(userBean);
                }else {
                    ToastUtils.showShort("注册失败");
                }
            }

            @Override
            public void onError( Throwable e) {
                Log.i(TAG, "regrequest-onError: ");
            }

            @Override
            public void onComplete() {
                Log.i(TAG, "regrequest-onError: ");
            }
        });
    }
    public void logrequest(String url,String user,String pass){
        Mmodel.log(url,user, pass, new Observer<UserBean>() {
            @Override
            public void onSubscribe( Disposable d) {
                Log.i(TAG, "logrequest-onSubscribe: ");
            }

            @Override
            public void onNext( UserBean userBean) {
                if (userBean.msg.equals("操作成功！")){
                    Vview.logOk(userBean);
                }else {
                    ToastUtils.showShort("登录失败");
                }
            }

            @Override
            public void onError( Throwable e) {
                Log.i(TAG, "logrequest-onError: ");
            }

            @Override
            public void onComplete() {
                Log.i(TAG, "logrequest-onError: ");
            }
        });
    }
}
